package cn.fl.risknew.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.overdue.condition.OverdueBaseCondition;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.risknew.service.IRiskOverdueService;
import cn.fl.risknew.vo.OverdueCstVO;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 *  逾期催收-我的任务
 *  作者:hongyanbo
 * 时间:2018/9/4
 */
@Controller
@RequestMapping("/risk/overdueCollect/")
public class MyTaskController {
    public static final Logger LOGGER = LoggerFactory.getLogger(MyTaskController.class);
    @Autowired
    private IRiskOverdueService overdueService;
    @Autowired
    private IPrjBscInfoService prjBscInfoService;//项目基础信息表
    @Autowired
    private ICstBscInfoService cstBscInfoService;
    @RequestMapping("/toMyTask.do")
    public ModelAndView toMyTask(ModelAndView model){
        //查询项目类型
        List<KeyValueVO> projectTypeList = this.prjBscInfoService.getProjectTypeList();
        model.addObject("projectTypeList", projectTypeList);
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        model.addObject("buOrgCdList", JSON.toJSONString(orgList));
        //查询第三方机构
        List<FriBaseInfoVO> list = this.overdueService.getFriBaseInfoList();
        model.addObject("friBaseList", list);
        // 所属区域
        List<KeyValueVO> regionList = this.prjBscInfoService.getRegionList();
        model.addObject("regionList", regionList);

        // 业务类型
        List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();
        model.addObject("bizTypeList",bizTypeList);
        // 逾期催收和我的任务公用一个JSP 用这个变量来区分列表查询
        model.addObject("view","myTask");
        model.setViewName("/risknew/ovdueCollect/myTaskList");
        return model;
    }
    @RequestMapping("/initMyTask.do")
    @ResponseBody
    public ListPageVO initMyTask(int page, int pagesize, OverdueBaseCondition condition){
        Pager pager = new Pager();
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());
        pager.setCondition(condition);
        pager.setEveryPage(pagesize);
        pager.setCurrentPage(page);
        pager = overdueService.initMyTaskPage(pager);
        List<OverdueCstVO> resultList = (List<OverdueCstVO>) pager.getResultList();
        ListPageVO<OverdueCstVO> res = null;
        res = new ListPageVO<>(resultList,pager.getTotalCount());
        return res;
    }

    @RequestMapping("exportMyTaskExcel.do")
    @ResponseBody
    public DataResultVO exportMyTaskExcel(OverdueBaseCondition condition){
        BaseLogUtils.info(LOGGER,"exportMyTaskExcel","逾期催收新-我的任务导出,操作人:"+CurrentThreadContext.getCurrentUserId());
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());
        condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
        return this.overdueService.exportMyTaskExcel(condition);
    }

    @RequestMapping("myTaskSum.do")
    @ResponseBody
    public OverdueCstVO getMyTaskSum(OverdueBaseCondition condition){
        condition.setUsrId(CurrentThreadContext.getCurrentUserId());
        return this.overdueService.getMyTaskSum(condition);
    }

}
